﻿//
// ********************************************************************
// * License and Disclaimer                                           *
// *                                                                  *
// * The  Geant4 software  is  copyright of the Copyright Holders  of *
// * the Geant4 Collaboration.  It is provided  under  the terms  and *
// * conditions of the Geant4 Software License,  included in the file *
// * LICENSE and available at  http://cern.ch/geant4/license .  These *
// * include a list of copyright holders.                             *
// *                                                                  *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work  make  any representation or  warranty, express or implied, *
// * regarding  this  software system or assume any liability for its *
// * use.  Please see the license in the file  LICENSE  and URL above *
// * for the full disclaimer and the limitation of liability.         *
// *                                                                  *
// * This  code  implementation is the result of  the  scientific and *
// * technical work of the GEANT4 collaboration.                      *
// * By using,  copying,  modifying or  distributing the software (or *
// * any work based  on the software)  you  agree  to acknowledge its *
// * use  in  resulting  scientific  publications,  and indicate your *
// * acceptance of all terms of the Geant4 Software license.          *
// ********************************************************************

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

#include "PhysicsList.hh"

#include <stdio.h>
#include <stdlib.h>

#include "G4DecayPhysics.hh"
#include "G4EmExtraPhysics.hh"
#include "G4EmStandardPhysics_option3.hh"
#include "G4HadronElasticPhysics.hh"
#include "G4HadronPhysicsQGSP_BIC.hh"
#include "G4IonBinaryCascadePhysics.hh"
#include "G4IonElasticPhysics.hh"
#include "G4IonPhysics.hh"
#include "G4LossTableManager.hh"
#include "G4NeutronTrackingCut.hh"
#include "G4StoppingPhysics.hh"
#include "G4SystemOfUnits.hh"
#include "G4Threading.hh"
#include "PhysicsListMessenger.hh"
// #include "MyMacros.hh"
// #include "G4Electron.hh"
// #include "G4EmStandardPhysics.hh"
// #include "G4EmStandardPhysics_option4.hh"
// #include "G4Gamma.hh"
// #include "G4HadronElasticPhysicsHP.hh"
// #include "G4HadronElasticPhysicsXS.hh"
// #include "G4IonPhysicsXS.hh"
// #include "G4ParticleTable.hh"
// #include "G4ParticleTypes.hh"
// #include "G4Positron.hh"
// #include "G4ProcessManager.hh"
// #include "G4Proton.hh"
// #include "G4RadioactiveDecayPhysics.hh"
// #include "G4AutoDelete.hh"

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

PhysicsList::PhysicsList() : G4VModularPhysicsList(), fEmPhysicsList(0), fDecayList(0), fHadronPhys(0)
{
    // given verbose level is set to all physics constructors. 越高越复杂.
    SetVerboseLevel(1);

    G4LossTableManager::Instance();
    defaultCutValue = 0.05 * mm;

    pMessenger = new PhysicsListMessenger(this);

    fDecayList = new G4DecayPhysics();
    fEmPhysicsList = new G4EmStandardPhysics_option3();
}

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

PhysicsList::~PhysicsList()
{
    delete pMessenger;
    delete fDecayList;
    delete fEmPhysicsList;
    for (size_t i = 0; i < fHadronPhys.size(); i++) delete fHadronPhys[i];
}

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

void PhysicsList::ConstructParticle() { fDecayList->ConstructParticle(); }

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

void PhysicsList::ConstructProcess()
{
    AddTransportation();

    fDecayList->ConstructProcess();
    fEmPhysicsList->ConstructProcess();

    for (size_t i = 0; i < fHadronPhys.size(); i++) fHadronPhys[i]->ConstructProcess();
}

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void PhysicsList::AddPhysicsList(const G4String& name)
{
    static auto fnAddEM = [this]()
    {
        delete fEmPhysicsList;
        fEmPhysicsList = new G4EmStandardPhysics_option3();
    };

    if (verboseLevel > 0)
    {
        G4cout << "PhysicsList::AddPhysicsList: <" << name << ">" << G4endl;
    }

    if (name == "emstandard_opt3")
    {
        fnAddEM();
    }
    else if (name == "QGSP_BIC_EMY")
    {
        fnAddEM();

        fHadronPhys.reserve(10);
        fHadronPhys.push_back(new G4EmExtraPhysics());
        fHadronPhys.push_back(new G4HadronElasticPhysics());
        fHadronPhys.push_back(new G4HadronPhysicsQGSP_BIC());
        fHadronPhys.push_back(new G4StoppingPhysics());
        fHadronPhys.push_back(new G4IonElasticPhysics());
        fHadronPhys.push_back(new G4IonPhysics());
        fHadronPhys.push_back(new G4NeutronTrackingCut());
        fHadronPhys.push_back(new G4IonBinaryCascadePhysics());
        fHadronPhys.shrink_to_fit();
    }
    else
    {
        G4cout << "PhysicsList::AddPhysicsList: <" << name << ">"
               << " is not defined" << G4endl;
    }
}

void PhysicsList::SetCuts()
{
    G4VUserPhysicsList::SetCuts();  //将粒子的截断设置为默认
}